import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

public class OJkuahao {
    public static void main(String[] args) {
        String string ="([a+b]-(rr{}))";
        boolean res =  match(string);
        System.out.println(res);
    }
    public static boolean match(String str) {
        Map<Character,Character> map = new HashMap<>();
        map.put(')', '(');
        map.put(']', '[');
        map.put('}', '{');
        Stack<Character> stack =new Stack<>();
        for(int i=0;i<str.length();i++) {
            Character c =str.charAt(i);
            if(map.containsValue(c)) {//左括号入栈
                stack.push(c);
            }
            else if(map.containsKey(c)) {//右括号出栈匹配
                if(stack.empty()) {
                    return false;
                }
                if(stack.peek()==map.get(c)) {
                    stack.pop();
                }else {
                    return false;
                }
            }

        }
        return stack.empty()?true:false;
    }
}

